package org.dromara.system.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.convert.Convert;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.constant.UserConstants;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.SysDeptBo;
import org.dromara.system.domain.bo.SysXzqhBo;
import org.dromara.system.domain.vo.SysDeptVo;
import org.dromara.system.domain.vo.SysXzqhVo;
import org.dromara.system.service.ISysDeptService;
import org.dromara.system.service.ISysPostService;
import org.dromara.system.service.ISysXzqhService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 行政区划信息
 *
 * @author Lion Li
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/xzqh")
public class SysXzqhController extends BaseController {

    private final ISysXzqhService xzqhService;

    /**
     * 获取行政区划
     */
    @SaCheckPermission("system:xzqh:list")
    @GetMapping("/list")
    public R<List<SysXzqhVo>> list(SysXzqhBo bo) {
        List<SysXzqhVo> list = xzqhService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 根据编号获取详细信息
     *
     * @param deptId 部门ID
     */
    @SaCheckPermission("system:dept:query")
    @GetMapping(value = "/{id}")
    public R<SysXzqhVo> getInfo(@PathVariable Long id) {
        return R.ok(xzqhService.queryById(id));
    }

    /**
     * 新增行政区划
     */
    @SaCheckPermission("system:xzqh:add")
    @PostMapping
    public R<Void> add(@Validated @RequestBody SysXzqhBo bo) {

        return toAjax(xzqhService.insertByBo(bo));
    }

    /**
     * 修改部门
     */
    @SaCheckPermission("system:xzqh:edit")
    @PutMapping
    public R<Void> edit(@Validated @RequestBody SysXzqhBo bo) {

        return toAjax(xzqhService.updateByBo(bo));
    }

    /**
     * 删除部门
     *
     * @param
     */
    @SaCheckPermission("system:dept:remove")
    @Log(title = "部门管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {

        return toAjax(xzqhService.deleteWithValidByIds(Arrays.asList(ids),true));
    }


}
